﻿using System;
using System.Collections.Generic;
using System.Linq;
using Illinois.Core.Interfaces;
using Illinois.Core.Models;
using Illinois.Core.Services;

namespace Illinois.Core.Fakes
{
  public class FakeUserRepository : IUserRepository
  {
    private readonly IEnumerable<Project> _projects;
    private readonly IEnumerable<User> _users;

    public FakeUserRepository()
    {
      _projects = MakeProjects();
      _users = MakeUsers(_projects);
    }

    private static IEnumerable<Project> MakeProjects()
    {
      var projects = new List<Project>();
      projects.Add(new Project { Id = 101, Name = "ARENA" });
      projects.Add(new Project { Id = 102, Name = "EBS" });
      return projects;
    }

    private static IEnumerable<User> MakeUsers(IEnumerable<Project> projects)
    {
      const string password = "098f6bcd4621d373cade4e832627b4f6";
      var users = new List<User>();
      users.Add(new User { Id = 101, Password = UserService.GetMd5Hash("mat"), UserName = "mattia.richetto", Project = projects.First(e => e.Id == 101) });
      users.Add(new User { Id = 102, Password = UserService.GetMd5Hash("mec"), UserName = "mariaelisa.cardone", Project = projects.First(e => e.Id == 102) });
      users.Add(new User { Id = 102, Password = UserService.GetMd5Hash("sav"), UserName = "savino.lovaglio", Project = projects.First(e => e.Id == 101) });
      return users;
    }

    public IEnumerable<User> FindAll()
    {
      throw new NotImplementedException();
    }

    public IEnumerable<User> Find(Func<User, bool> predicate)
    {
      return _users.Where(predicate);
    }

    public User FindById(int id)
    {
      throw new NotImplementedException();
    }

    public void Add(User newEntity)
    {
      throw new NotImplementedException();
    }

    public void Remove(User entity)
    {
      throw new NotImplementedException();
    }
  }
}
